﻿using BW.IBll;
using BW.IDal;
using BW.Model;

namespace BW.Bll
{
    public class RoerlBll : IRoerlbLL
    {

        public RoerlBll(IBaerDal<Roerl> baerDa, IBaerDal<StatesType> baerD)
        { 
            BaerDa = baerDa;
            BaerD = baerD;
        }

        public IBaerDal<Roerl> BaerDa { get; }
        public IBaerDal<StatesType> BaerD { get; }

        /// <summary>
        /// 查询显示
        /// </summary>
        /// <param name="name">姓名</param>
        /// <param name="statesTypeId">职业id</param>
        /// <returns>通过姓名，职业查询数据获取一条数据</returns>
        public dynamic ShowRoerl(string? name, int statesTypeId)
        {
            var roerl = BaerDa.GetAllAnync();
            var statesType = BaerD.GetAllAnync();
            var linq = from a in roerl
                       join b in statesType
                        on a.StatesTypeId equals b.StatesTypeId
                       select new
                       {
                           a.RoerlNama,
                           a.RoerlDate,
                           a.State,
                           a.RoerlId,
                           a.Adds,
                           a.StatesTypeId,
                           a.Sex,
                           a.IdCord,
                           a.Phone,
                           b.StatesTypeName,
                        


                       };

            if (!string.IsNullOrEmpty(name)) {

                linq = linq.Where(x => x.RoerlNama.Contains(name));

            }

            if (statesTypeId>0)
            {

                linq = linq.Where(x => x.StatesTypeId.Equals(statesTypeId));

            }

            return linq.ToList();





        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="t">数据信息</param>
        /// <returns>返回受影响行数</returns>
        public async Task<int> AddAnync(Roerl roerl)
        {
              return await BaerDa.AddAnync(roerl);

        }

     
    }
}
